package com.yuejian_06.yuejian_06.activity;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.yuejian_06.yuejian_06.Listener.MeListener;
import com.yuejian_06.yuejian_06.R;
import com.yuejian_06.yuejian_06.adapter.OrderAdapter;
import com.yuejian_06.yuejian_06.adapter.PostAdapter;
import com.yuejian_06.yuejian_06.bean.OrderListBean;
import com.yuejian_06.yuejian_06.bean.PostListBean;
import com.yuejian_06.yuejian_06.model.MeModel;

import java.util.List;

public class OrderListActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private SwipeRefreshLayout activity_order_list;
    @Override
    void initViews() {

    }

    @Override
    void initEvents() {

    }

    @Override
    void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_list);
        recyclerView = (RecyclerView) findViewById(R.id.ol_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(OrderListActivity.this));
        MeModel meModel = new MeModel();
        meModel.getOrderList(getUser_id(),meListener);

        //下拉刷新
        activity_order_list = (SwipeRefreshLayout) findViewById(R.id.activity_order_list);
        activity_order_list.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override public void onRefresh() {
                //重新获取数据
                MeModel meModel = new MeModel();
                meModel.getOrderList(getUser_id(),meListener1);
                //获取完成
                activity_order_list.setRefreshing(false);
            }
        });

    }
    private MeListener<List<OrderListBean>> meListener = new MeListener<List<OrderListBean>>() {
        @Override
        public void onResponse(List<OrderListBean> o) {
            List<OrderListBean> res=o;
            List<OrderListBean> mDataList =(List) res;
            recyclerView.setAdapter(new OrderAdapter(OrderListActivity.this,mDataList));
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(OrderListActivity.this,"activity失败了",Toast.LENGTH_SHORT).show();
        }
    };

    //刷新
    private MeListener<List<OrderListBean>> meListener1 = new MeListener<List<OrderListBean>>() {
        @Override
        public void onResponse(List<OrderListBean> o) {
            List<OrderListBean> res=o;
            List<OrderListBean> mDataList =(List) res;
            recyclerView.setAdapter(new OrderAdapter(OrderListActivity.this,mDataList));
            Toast.makeText(OrderListActivity.this,"订单刷新成功",Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(OrderListActivity.this,"activity失败了",Toast.LENGTH_SHORT).show();
        }
    };
}
